<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div></div>
    <script src="../jquery-1.12.4.js"></script>
    <script>
        $(function() {
            var arr = [{
                id: 1,
                name: 'apple',
            }, {
                id: 2,
                name: 'eggplant',
            }, {
                id: 3,
                name: 'lemon',
            }];
            var ftag = `<ul>`;
            arr.forEach(function(item, index) {
                ftag += `<li data-abc='hello' data-id='${item.id}'>${item.name}</li>`;
            })
            ftag += `</ul>`
                // console.log(ftag);
            $('div').append(ftag);

            var ul = $('ul');
            ul.eq(0).click(function(e) {
                console.log(e.target.dataset.id);
            })
        })
    </script>
</body>

</html>